home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_06_05 / v6n5070a.txt < prev    next >
Text File  |  1989-09-26  |  3KB  |  68 lines

  1.  
  2. name  set_env
  3. COMMENT;------------------------------------------------------
  4. Purpose: to write directly to the original environment using 
  5. undocumented interrupt number 2Eh - For command line usage: 
  6. set_env string_name Revised/Reassembled Under MASM v.5.0 03/02/88 
  7. - Ron Schroeder First assemble, link and then use EXE2BIN to 
  8. convert to .com file   
  9.  
  10. ;-----------------------------
  11. code_seg       segment
  12.                assume cs:code_seg, ds:code_seg,es:code_seg,ds:code_seg
  13.                org       100h           ; com file format
  14.  
  15. main           proc      near
  16.  
  17.                jmp       short  START   ;skip over data area
  18.        
  19. ;----------------------------------------------------------------
  20.  
  21. set            db        ODh            ; chars in `SET STRING=` (11)
  22.                db        'SET STRING='  ;environmental literal
  23. setting        db        20h   dup(0)   ;arbitrary size envp buffer
  24. ;----------------------------------------------------------------
  25.  
  26. START:         mov       ah,4Ah         ; first modify memory location
  27.                mov       bx,offset FREE ; make room for command.com
  28.                dec       bx
  29.                mov       cl,o4h
  30.                shr       bx,cl
  31.                inc       bx
  32.                int       21h            ; do it
  33.  
  34.                xor       ch,ch          ; zero out ch (defensive move
  35.                mov       si,0080h       ; get command line length
  36.                mov       cl,byte ptr[si]; put it in cl
  37.                dec       cl             ; adjust it
  38.                jcxz      ERROR1         ; error if no command line    
  39.                add       set,cl         ; add cmd line size to literal
  40.                mov       si,0082h       ; beginning of command line
  41.                mov       di,offset setting  ; destination 
  42.                rep       movsb          ; put all in setting for length
  43.                                         ; in cx
  44.                xor       bh,bh          ; zero out bh (defensive move)
  45.                mov       bl,set         ; 'new' length of env string
  46.                mov       set[bx][1],0Dh ;0Dh is cr at end of string
  47.                mov       si,offset set
  48.                int     2Eh              ; write ds:si to original environment
  49.                
  50.                xor      al,al          ; zero out al for zero error code ret 
  51.  
  52. EXIT:          mov       ah,4Ch         ; quit
  53.                int       21h
  54.  
  55. ERROR1:        mov       al,01h         ; if no characters entered
  56.                jmp       short EXIT     ; then error
  57.  
  58. FREE           label     byte           ; to determine memory
  59.                                         ; allocation for this program
  60. main           endp                     ; end of procedure
  61.  
  62. ;----------------------------------------------------------------
  63.  
  64. code_seg       ends
  65.                end       main
  66.  
  67.  
  68.